package com.ning.parking.config;

import com.github.benmanes.caffeine.cache.RemovalCause;
import com.github.benmanes.caffeine.cache.RemovalListener;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

import javax.websocket.Session;
import java.io.IOException;

/**
 * @Author ChenN
 * @Date 2025/1/16 14:38
 * @Version 0.0.1
 **/
@Slf4j
public class WebSocketRemovalListener implements RemovalListener<String, Session> {

    @Override
    public void onRemoval(@Nullable String key, @Nullable Session session, @NonNull RemovalCause removalCause) {

        try {
            if (session !=null){
                log.error("[{}] 过期删除 PATH:{}",key,session.getRequestURI());
                session.close();
            }
        } catch (IOException e) {
            log.error("{}",e);
        }
    }
}
